package org.anderground.editor.edits;

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CompoundEdit;

import org.anderground.core.model.Line;
import org.anderground.core.model.ModelData;
import org.anderground.core.model.Station;
import org.anderground.core.model.Transition;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
public abstract class DataAction extends Action {

	private ModelData data;
	private Station[] stations;
	private Transition[] transitions;
	private Line[] lines;

	/**
	 * @param data
	 * @param stations
	 * @param transitions
	 */
	public DataAction(ModelData data, Station[] stations,
			Transition[] transitions) {
		if (data == null) {
			throw new IllegalArgumentException("modelData cannot be null");
		}
		this.data = data;
		this.stations = stations;
		this.transitions = transitions;
	}

	/**
	 * @return the data
	 */
	protected ModelData getData() {
		return data;
	}

	/**
	 * @return the stations
	 */
	protected Station[] getStations() {
		return stations;
	}

	/**
	 * @return the transitions
	 */
	protected Transition[] getTransitions() {
		return transitions;
	}

	/**
	 * 
	 * @return the lines
	 */
	protected Line[] getLines() {
		return lines;
	}

	/**
	 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
	 */
	@SuppressWarnings("serial")
	protected static abstract class DataEdit extends CompoundEdit {

		/**
		 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
		 */
		protected abstract class AtomicDataEdit extends AbstractUndoableEdit {
		}

		private ModelData data;

		public DataEdit(ModelData data) {
			this.data = data;
		}

		/**
		 * @return the data
		 */
		public ModelData getData() {
			return data;
		}

		@Override
		public boolean isSignificant() {
			return true;
		}

	}

}
